package com.rf.richfitwheel.admin.sys.controller;

import com.rf.richfitwheel.admin.annotation.UserOperateLog;
import com.rf.richfitwheel.admin.contants.UrlConstant;
import com.rf.richfitwheel.admin.sys.model.CodeDef;
import com.rf.richfitwheel.admin.sys.service.CodeDefService;
import com.rf.richfitwheel.common.utils.PageUtils;
import com.rf.richfitwheel.common.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * Author bw
 * Date  2019-05-05
 */
@RestController
@RequestMapping(value = UrlConstant.WEB_ADMIN_URL+"/codeDef")
public class CodeDefController {
    @Autowired
    private CodeDefService codeDefService;

    @GetMapping("/list")
    public R list(@RequestParam Map<String, Object> params) {
    	PageUtils page = codeDefService.queryPage(params);
		return R.ok().put("page", page);
    }

    /**
     * 根据id查询编码定义信息
     * @param id
     * @return
     */
    @GetMapping("/info/{id}")
    public R get(@PathVariable("id") String id){
        CodeDef codeDef = codeDefService.get(id);
        return R.ok().put("codeDef", codeDef);
    }
    /**
     * 添加编码定义信息
     * @param codeDef
     * @return
     */
    @UserOperateLog(module="系统功能",methods="addCodeDef",description="添加编码定义信息")
    @PostMapping("/addCodeDef")
    public R addCodeDef(@RequestBody CodeDef codeDef) {
      return codeDefService.insert(codeDef);
    }

    @UserOperateLog(module="系统功能",methods="insertBatch",description="批量添加编码定义信息")
    @RequestMapping(value = "/insertBatch", method = RequestMethod.POST)
    public String insertBatch(@RequestBody List<CodeDef> codeDefs) {
        if (codeDefService.insertBatch(codeDefs) > 0) {
            return "success";
        } else {
            return "failed";
        }
    }

    /**
     * 更新编码定义信息
     * @param codeDef
     * @return
     */
    @UserOperateLog(module="系统功能",methods="update",description="更新编码定义信息")
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    public R update(@RequestBody CodeDef codeDef) {
       return codeDefService.update(codeDef);
    }

    /**
     * 删除编码定义信息
     * @param ids
     * @return
     */
    @UserOperateLog(module="系统功能",methods="delete",description="删除编码定义信息")
    @PostMapping("/delete")
    public R delete(@RequestBody String[] ids) {
       return codeDefService.delete(ids);
    }

}
